--------------------------------------------------------------------------------
-- File: marquage_accessible.adb
--------------------------------------------------------------------------------
with Text_Io; use Text_Io;

package body marquage_accessible is

    Package Io is new Integer_Io(Integer);

    ----------------------------------------------
    -- PROCEDURE create
    -- Initialise le Marquage Accessible
    ----------------------------------------------
    procedure create  (marqAcc : in out MarquageAccessible; marq : in Marquage) is
        marqZero : tabMarquage;
    begin
        for i in 1..nbTransition loop
            marqZero(i) := -1;
        end loop;
        marqAcc.M := marq;
        marqAcc.suivant := marqZero;
    end create;


    ----------------------------------------------
    -- PROCEDURE Put
    -- Affiche le Marquage Accessible
    ----------------------------------------------
    procedure Put     (marqAcc : in MarquageAccessible; iterator : in Integer) is
        i : Integer := 0 ;
        j : Integer := 0 ;
    begin
        Put("M" & Integer'Image(iterator-1) & " : [");
        for i in 1 .. nbPlace loop
            Put(Integer'Image(marqAcc.M(i)) & " ");
        end loop;
        Put_Line("]");
        Put_Line("Suiv :");
        for j in 1 .. nbTransition loop
            if (marqAcc.suivant(j) /= -1) then
                Put_Line("T : " & Integer'Image(j) & " ->" & Integer'Image(marqAcc.suivant(j)-1));
            end if;
        end loop;
        New_Line;
    end Put;


  ----------------------------------------------
  -- FUNCTION Egal
  -- Test si les deux marquages sont egaux
  ----------------------------------------------
    function  Egal    (marq1 : in Marquage; marq2 : in Marquage) return Boolean is
    begin
        for i in 1..nbPlace loop
            if marq1(i) /= marq2(i) then
                return false;
            end if;
        end loop;
        return true;
    end Egal;

    function  isNull     (marq : in Marquage) return Boolean is
    begin
        for i in 1..nbPlace loop
            if (marq(i) /= 0) then
                return false;
            end if;
        end loop;
        return true;
    end isNull;


  ----------------------------------------------
  -- FUNCTION SupEgal
  -- Test si 'marq1' couvre 'marq2'
  ----------------------------------------------
    function  SupEgal     (marq1 : in Marquage; marq2 : in Marquage) return Boolean is
    begin
        if (isNull(marq2))
            then return false;
        end if;
        for i in 1..nbPlace loop
            if (marq1(i) < marq2(i)) then
                return false;
            end if;
        end loop;
        return true;
    end SupEgal;


  ----------------------------------------------
  -- FUNCTION BecomeMultiple
  -- Transforme un marquage quelconque en un marquage multiple
  ----------------------------------------------
    procedure BecomeMultiple (marq1 : in out Marquage; marq2 : in Marquage) is
    begin
        for i in 1..nbPlace loop
            if (marq1(i) > marq2(i)) then
                marq1(i) := -1;
            end if;
        end loop;
    end BecomeMultiple;

end marquage_accessible;

